class Solution:
    def canPartition(self, nums) :
        nums.sort()
        i = 0
        j = len(nums)-1
        sum = 0
        sum1 = 0
        while i<=j:
            if (sum + nums[i])<=sum1:
                sum = sum +nums[i]
                i = i + 1
            else:
                sum1 = sum1 + nums[j]
                j = j-1
        if sum==sum1:
            return True
        else:
            return False

if __name__ == '__main__':
    S = Solution()
    T = S.canPartition([1,2,3,4])
    print(T)